<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button v-waves class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-back" @click="handleBack">返回</el-button>
      <span style="font-size:12px;">该列表显示属于角色【普通职员】下的所有权限</span>
    </div>
    <el-input
      v-model="filterText"
      placeholder="输入关键字进行过滤"/>
    <el-tree
      ref="tree2"
      :data="data2"
      :default-expanded-keys="[12, 17]"
      :default-checked-keys="[1,3]"
      :props="defaultProps"
      show-checkbox
      node-key="id"
      highlight-current
    />
  </div>
</template>

<script>

export default {
  data() {
    return {
      filterText: '',
      data2: [{
        id: 1,
        label: '仪表盘'
      }, {
        id: 2,
        label: '用户-权限管理',
        children: [{
          id: 3,
          label: '角色管理',
          children: [{
            id: 5,
            label: '查看' },
          {
            id: 6,
            label: '新增'
          },
          {
            id: 7,
            label: '编辑'
          },
          {
            id: 8,
            label: '授权'
          },
          {
            id: 9,
            label: '删除'
          },
          {
            id: 10,
            label: '查看用户列表'
          },
          {
            id: 11,
            label: '移除用户列表'
          },
          {
            id: 12,
            label: '授权功能'
          }
          ]
        }, {
          id: 4,
          label: '用户管理',
          children: [
            {
              id: 13,
              label: '查询'
            },
            {
              id: 14,
              label: '查看'
            },
            {
              id: 15,
              label: '新增'
            },
            {
              id: 16,
              label: '编辑'
            },
            {
              id: 17,
              label: '删除'
            }
          ]
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },
  created() {
  },
  methods: {
    // 返回
    handleBack() {
      this.$router.push({ name: 'Role' })
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    }
  }
}
</script>
